#!/usr/bin/python3.8
# coding:utf-8
# zabbix钉钉告警脚本

import requests, sys, json

user = sys.argv[1]
text = sys.argv[2]
token = sys.argv[3]

webhook = "https://oapi.dingtalk.com/robot/send?access_token={}".format(token)

data = {
    "msgtype": "text",
    "text": {
        "content": text
    },
    "at": {
        "atMobiles": [
            user
        ],
        "isAtAll": False
    }
}

headers = {'Content-Type': 'application/json'}

requests.post(url=webhook, data=json.dumps(data), headers=headers)
